﻿@model Leads360Express.Repository.Pages.Reporting.LeadFunnelModel
@{
    Layout = "~/Views/Shared/_Layout..cshtml";
    ViewBag.Title = "Lead Funnel";

    // Local variables
    //string strFrom = DateTime.Now.AddDays(-7).ToShortDateString();
    //string strTo = DateTime.Now.ToShortDateString();
}
<form method="post" class="form" id="reportLeadFunnel">
    <fieldset>

        <div class="content">
            <h2 class="app">
                <strong>Lead Funnel Report</strong>
                @Html.Partial("_PatialLeads_Calls", @Model.LeadCall)
            </h2>
            <div id="viewFunnel" class="toolbar topblue">
                <span class="area">
                    <span class="spl" style=""><strong>View:</strong></span>
                    <input type="radio" name="funnelFilter" class="radio spl" value="ByUser" data-bind="checked: viewType" />
                    <span class="spl">Users</span>
                    <input type="radio" name="funnelFilter" class="radio spl" value="ByCampaign" data-bind="checked: viewType" />
                    <label for="txt-from" class="spl" style="font-weight:normal;">Lead Sources</label>
                </span>

                <span class="area">
                    <div class="select-holder sel-range spl" style="width:172px; margin-right:0;">
                        <select id="select1" style="width:172px;" data-bind="value: LeadOption, foreach: LeadSource, enable: LeadSourceSelected">
                            <option data-bind="value: Id, text: Name"></option>
                        </select>
                    </div>
                </span>

                <span class="area">
                    <label for="txt-from" class="spl" style="font-weight:normal;padding-left:5px;">From:</label>
                    <input type="text" id="startDate" class="text date spl" data-bind="value: StartDate" />
                    @*<input type="text" id="startDate" class="text date spl" value="@strFrom" />*@
                    <label for="txt-from" class="spl" style="font-weight:normal;padding-left:5px;">To:</label>
                    <input type="text" id="endDate" class="text date" data-bind="value: EndDate" />
                    @*<input type="text" id="endDate" class="text date" value="@strTo" />*@
                </span>

                <span class="area left">
                    <a href="#" class="btn btn-go" data-bind="click: GoFilter">Go</a>
                </span>
            </div>
            @if (Model != null && Model.FunnelInfo != null && Model.FunnelInfo.Total > 0)
            {
                <div id="gridview" data-bind="simpleGrid: gridViewModel"></div>
            }
            else
            {
                <div class="panel">
                    <div class="error-msg"><span>No results were found.</span></div>
                </div>
            }

            @Html.Partial("_Footer.Copyright")
        </div><!-- //.content -->

    </fieldset>
</form>
@if (Model != null && Model.FunnelInfo != null && Model.FunnelInfo.Total > 0)
{
    <script src="/Scripts/viewModel/viewmodel.funnelreport.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
        var initialData = [
            @Html.Raw(Model.ArrayData.ArrayText)
        ];

        var initialHeader = [
            @Html.Raw(Model.ArrayData.ArrayHeader)
        ];

        var PagedGridModel = function(items, headers) {
            this.items = ko.observableArray(items);
            this.headers = ko.observableArray(headers);

            this.jumpToFirstPage = function() {
                this.gridViewModel.currentPageIndex(0);
            };

            this.gridViewModel = new ko.simpleGrid.viewModel({
                columns: this.headers,
                data: this.items,
                pageSize: 10
            });
        };

        ko.applyBindings(new PagedGridModel(initialData, initialHeader), document.getElementById("gridview"));
    //]]>
    </script>
}
<script type="text/javascript">
//<![CDATA[
    var data = @Html.Raw(Json.Encode(Model));
    $(function () {
        $("#startDate").datepicker();
        $("#endDate").datepicker();
    });
//]]>
</script>
<script src="/Scripts/viewModel/viewFunnelReport.js" type="text/javascript"></script>
